package com.zenglx.demo;

import com.zenglx.assembly.avoidRepeatSubmit.RepeatSubmit;
import com.zenglx.assembly.increasingSequence.api.SequenceGeneratorApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 服务启动入口
 * @author zlx
 */
@RestController
@Api(value = "组件测试接口", tags = {"组件测试接口"})
public class AssemblyDemoTest {
    @Autowired
    private SequenceGeneratorApi sequenceGeneratorApi;

    @GetMapping("/testSequence")
    @ApiOperation(value = "测试递增序列", notes = "返回结果")
   public String testSequence() {
        for(int i=0;i<10;i++){
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    System.out.println("线程名:"+Thread.currentThread().getName()
                            +":"+sequenceGeneratorApi.nextId("default-lock"));
                }
            });
            thread.start();
        }
        return null;
   }

    @PostMapping("/testRepeatSubmit")
    @RepeatSubmit
    @ApiOperation(value = "测试重复提交", notes = "返回结果")
    public String testRepeatSubmit(@RequestBody String param) {

        System.out.println("重复提交测试");
        return null;
    }

}
